﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TY.Utilities;
using System.Collections;
using System.IO;

namespace TY_75Stability.WinApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var t1 = ReadHelper.ReadTxtFile("E:\\新建文件夹 (11)\\1_1.json");
            var r1 = JsonHelper.JonsToList<ArrayList>(t1);
            var tt1 = r1.Select(x => DateTimeHelper.GetTime(x[0].ToString())).ToList();
            var tt2 = r1.Select(x => Convert.ToInt64(x[0].ToString())).ToList();
            var d1 = r1.Select(x => Utils.ObjToFloat(Utils.CutStringReal(x[1].ToString(),6), 0)).ToList();

            List<double[]> txtList = new List<double[]>();
            Random r = new Random();
            for (int i = 0; i < d1.Count; i++)
            {
                //var l= r.Next(1, 9);
                //double h = (l / 1000.0);
                var f =Math.Round((float)(d1[i] + 0.06), 3);
                txtList.Add(new double[] { tt2[i], f });
            }

            File.WriteAllText("6_1.json", JSON.Encode(txtList));
            return;

            //List<double> caleList = new List<double>();
            //double cz = 0;
            //List<float> avgList = new List<float>();

            //List<double[]> txtList = new List<double[]>();
            //for (int i = 0; i < d1.Count; i++)
            //{

            //    double zhi = 0;
            //    if (cz == 0)
            //    {
            //        avgList.Add(d1[i]);
            //        cz = d1[i];


            //    }
            //    else
            //    {
            //        zhi = d1[i] - ((d1[i] - cz) * 0.9995);
            //        avgList.Add((float)Math.Round(zhi, 3));
            //        cz = zhi;
            //    }
            //    txtList.Add(new double[] { tt2[i], cz });
            //}

            //var ddddd = avgList.Max();
            //var xxxxx = avgList.Min();
            //var gg = avgList.Average();
            //d1 = avgList;
            //d1.RemoveRange(0, 10);
            //d1.Sort();
            //File.WriteAllText("2_3.json", JSON.Encode(txtList));
            //return;
            //d1.RemoveRange(0, 10);
            //d1.RemoveRange(d1.Count - 10, 10);
            //label4.Text = label4.Text + d1.Max();
            //label5.Text = label5.Text + d1.Min();
            //label18.Text = label18.Text + Math.Round(Utils.CalculateStdDev(d1), 3);
            //label3.Text = label3.Text + Math.Round(d1.Max() - d1.Min(), 3);
            //label6.Text = label6.Text + d1.Average();

            //var t2 = ReadHelper.ReadTxtFile("E:\\新建文件夹 (15)\\1_2.json");
            //var r2 = JsonHelper.JonsToList<ArrayList>(t2);
            //var d2 = r2.Select(x => Utils.ObjToFloat(Utils.CutStringReal(x[1].ToString(), 5), 0)).ToList();
            //d2.RemoveRange(0, 20000);
            //d2.Sort();


            ////d2.RemoveRange(0, 10);
            ////d2.RemoveRange(d2.Count - 10, 10);
            //label8.Text = label8.Text + d2.Max();
            //label7.Text = label7.Text + d2.Min();
            //label17.Text = label17.Text + Math.Round(Utils.CalculateStdDev(d2), 3);
            //label14.Text = label14.Text + Math.Round(d2.Max() - d2.Min(), 2);
            //label9.Text = label9.Text + d2.Average();

            //var t3 = ReadHelper.ReadTxtFile("E:\\新建文件夹 (15)\\1_3.json");
            //var r3 = JsonHelper.JonsToList<ArrayList>(t3);
            //var d3 = r3.Select(x => Utils.ObjToFloat(Utils.CutStringReal(x[1].ToString(), 5), 0)).ToList();
            //d3.RemoveRange(0, 20000);
            //d3.Sort();


            ////d3.RemoveRange(0, 10);
            ////d3.RemoveRange(d3.Count - 10, 10);
            //label12.Text = label12.Text + d3.Max();
            //label11.Text = label11.Text + d3.Min();
            //label16.Text = label16.Text + Math.Round(Utils.CalculateStdDev(d3), 3);
            //label15.Text = label15.Text + Math.Round(d3.Max() - d3.Min(), 3);
            //label10.Text = label10.Text + d3.Average();

            ////StreamWriter sw = new StreamWriter("E:/file.txt", true, System.Text.Encoding.Default);


            ////for (int i = 0; i < d1.Count; i++)
            ////{
            ////    sw.WriteLine(string.Format("{0}   {1}   {2}   {3}", tt1[i], d1[i],d2[i],d3[i]));
            ////}
            ////sw.Close();
        }
    }
}
